package com.ww.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Administrator
 * @desc ww
 */
@Configuration
public class RabbitFanoutMqConfig {

    /**
     * 广播模式
     */
    private static final String FANOUT_QUEUE01 = "fanout_queue_01";
    private static final String FANOUT_QUEUE02 = "fanout_queue_02";
    private static final String FANOUT_EXCHANGE = "fanoutExchange";

    /**
     * 广播队列
     *
     * @return 定义结果
     */
    @Bean
    public Queue fanoutQueue01() {
        return new Queue(FANOUT_QUEUE01);
    }
    @Bean
    public Queue fanoutQueue02() {
        return new Queue(FANOUT_QUEUE02);
    }

    /**
     * 交换机
     *
     * @return 定义结果
     */
    @Bean
    public FanoutExchange fanoutExchange() {
        return new FanoutExchange(FANOUT_EXCHANGE);
    }

    /**
     * 绑定交换机与队列
     *
     * @return  绑定结果
     */
    @Bean
    public Binding binding01() {
        return BindingBuilder.bind(fanoutQueue01()).to(fanoutExchange());
    }
    @Bean
    public Binding binding02() {
        return BindingBuilder.bind(fanoutQueue02()).to(fanoutExchange());
    }

}
